package com.mye.prometheusexportdcim.utils;


import org.apache.commons.lang3.StringUtils;
import org.springframework.util.CollectionUtils;

import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;


/**
 * @创建人 hch
 * @创建时间 2020/7/28 15:06
 * @描述 TODO
 * @版本 1.0.0
 */
public class CodingUtils {


    public static String getList2String2(List<Integer> list) {
        if (CollectionUtils.isEmpty(list)) {
            return null;
        }
        StringBuilder builder = new StringBuilder();
        builder.append(" ( ");
        String join = StringUtils.join(list, ",");
        builder.append(join);
        builder.append(" ) ");
        return builder.toString();

    }

    public static String getList2String3(List<String> list) {
        if (CollectionUtils.isEmpty(list)) {
            return null;
        }
        list = list.stream().filter(Objects::nonNull).map(s -> "'" + s + "'").collect(Collectors.toList());
        StringBuilder builder = new StringBuilder();
        builder.append(" ( ");
        String join = StringUtils.join(list, ",");
        builder.append(join);
        builder.append(" ) ");
        return builder.toString();

    }

    /**
     * 使用list自带的sort方法先进性排序，然后转成toString去判断两个集合是否相等
     */
    public static boolean checkDiffrent5(List<Integer> list, List<Integer> list1) {
        long st = System.nanoTime();
        System.out.println("消耗时间为： " + (System.nanoTime() - st));
        list.sort(Comparator.comparing(Integer::intValue));
        list1.sort(Comparator.comparing(Integer::intValue));
        return list.toString().equals(list1.toString());
    }


}
